package com.cw.jeeyt.service.converter.api;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.cw.jeeyt.service.bo.api.ApiDatabaseDocBo;
import com.cw.jeeyt.dao.model.api.ApiDatabaseDocDo;
import com.cw.lang.common.utils.CollectionUtil;

/**
 * 数据库信息转换类
 *
 * @author chenw
 * @date 2019-03-10 13:05:36
 */
public class ApiDatabaseDocConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static ApiDatabaseDocBo do2Bo(ApiDatabaseDocDo model) {
        if (model == null) {
            return null;
        }
        ApiDatabaseDocBo bo = new ApiDatabaseDocBo();
        bo.setId(model.getId());
        bo.setDatabaseCode(model.getDatabaseCode());
        bo.setDatabaseName(model.getDatabaseName());
        bo.setDatabaseType(model.getDatabaseType());
        bo.setJdbcDialact(model.getJdbcDialact());
        bo.setJdbcUrl(model.getJdbcUrl());
        bo.setJdbcDriverClass(model.getJdbcDriverClass());
        bo.setJdbcUserName(model.getJdbcUserName());
        bo.setJdbcUserPassword(model.getJdbcUserPassword());
        bo.setCreateBy(model.getCreateBy());
        bo.setCreateDate(model.getCreateDate());
        bo.setUpdateBy(model.getUpdateBy());
        bo.setUpdateDate(model.getUpdateDate());
        return bo;
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static ApiDatabaseDocDo bo2Do(ApiDatabaseDocBo bo) {
        if (bo == null) {
            return null;
        }
        ApiDatabaseDocDo model = new ApiDatabaseDocDo();
        model.setId(bo.getId());
        model.setDatabaseCode(bo.getDatabaseCode());
        model.setDatabaseName(bo.getDatabaseName());
        model.setDatabaseType(bo.getDatabaseType());
        model.setJdbcDialact(bo.getJdbcDialact());
        model.setJdbcUrl(bo.getJdbcUrl());
        model.setJdbcDriverClass(bo.getJdbcDriverClass());
        model.setJdbcUserName(bo.getJdbcUserName());
        model.setJdbcUserPassword(bo.getJdbcUserPassword());
        model.setCreateBy(bo.getCreateBy());
        model.setCreateDate(bo.getCreateDate());
        model.setUpdateBy(bo.getUpdateBy());
        model.setUpdateDate(bo.getUpdateDate());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<ApiDatabaseDocBo> doList2BoList(List<ApiDatabaseDocDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), ApiDatabaseDocConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<ApiDatabaseDocDo> boList2DoList(List<ApiDatabaseDocBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), ApiDatabaseDocConverter::bo2Do));
    }
}